// Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
using Microsoft.WindowsAPICodePack.DirectX.DirectWrite;

namespace D2DPaint
{
    public partial class TextDialog : Form
    {
        private Pain2DForm parent;
        internal TextLayout textLayout = null;
        public TextDialog(Pain2DForm parent, float maxX, float maxY)
        {
            InitializeComponent();

            this.fontFamilyCombo.SelectedIndex = 0; // First Choice
            this.sizeCombo.SelectedIndex = 4; // 12.0
            this.weightCombo.SelectedIndex = 3; // Normal
            this.styleCombo.SelectedIndex = 0; // Normal
            this.stretchCombo.SelectedIndex = 5; // Normal

            this.parent = parent;
        }

        private void AddTextButton_Click(object sender, EventArgs e)
        {
            TextFormat textFormat = parent.dwriteFactory.CreateTextFormat(
                this.fontFamilyCombo.Text,
                float.Parse(this.sizeCombo.Text),
                (FontWeight)((this.weightCombo.SelectedIndex + 1) * 100),
                (FontStyle)styleCombo.SelectedIndex,
                (FontStretch)stretchCombo.SelectedIndex,
                "");
            this.textLayout = parent.dwriteFactory.CreateTextLayout(this.textBox.Text, textFormat, 100, 100);
            if (this.underLineCheckBox.Checked)
            {
                textLayout.SetUnderline(true, new TextRange((uint)0, (uint)this.textBox.Text.Length));
            }
            if (this.strikethroughCheckBox.Checked)
            {
                textLayout.SetStrikethrough(true, new TextRange((uint)0, (uint)this.textBox.Text.Length));
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
            

        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();

        }


    }
}
